import request from '@/utils/request'

// 查询能源数据列表
export function listEnergyData(query) {
  return request({
    url: '/energy/monitor/list',
    method: 'get',
    params: query
  })
}

// 查询所有设备最新能源数据
export function getLatestData() {
  return request({
    url: '/energy/monitor/latest',
    method: 'get'
  })
}

// 根据设备ID查询最新数据
export function getLatestDataByDevice(deviceId) {
  return request({
    url: '/energy/monitor/latest/' + deviceId,
    method: 'get'
  })
}

// 查询能源数据统计
export function getEnergyStatistics(params) {
  return request({
    url: '/energy/monitor/statistics',
    method: 'get',
    params: params
  })
}

// 查询能源数据趋势
export function getEnergyTrend(params) {
  return request({
    url: '/energy/monitor/trend',
    method: 'get',
    params: params
  })
}

// ==================== 图表数据接口 (新增) ====================

// 获取趋势图数据
export function getChartTrendData(params) {
  return request({
    url: '/energy/charts/trend',
    method: 'get',
    params: params
  })
}

// 获取能耗分布数据
export function getChartDistributionData(params) {
  return request({
    url: '/energy/charts/distribution',
    method: 'get',
    params: params
  })
}

// 获取设备效率分析数据
export function getChartEfficiencyData(deviceCode, params) {
  return request({
    url: '/energy/charts/efficiency/' + deviceCode,
    method: 'get',
    params: params
  })
}

// 获取负载分析数据
export function getChartLoadData(deviceCode, params) {
  return request({
    url: '/energy/charts/load/' + deviceCode,
    method: 'get',
    params: params
  })
}

// ==================== TDengine数据查询接口 (新增) ====================

// 查询设备采集数据历史记录
export function getCollectionHistory(deviceCode, params) {
  return request({
    url: '/energy/collection/history/' + deviceCode,
    method: 'get',
    params: params
  })
}

// 查询设备最新采集数据
export function getLatestCollectionData(deviceCode) {
  return request({
    url: '/energy/collection/latest/' + deviceCode,
    method: 'get'
  })
}

// 查询设备采集数据统计
export function getCollectionStatistics(deviceCode, params) {
  return request({
    url: '/energy/collection/statistics/' + deviceCode,
    method: 'get',
    params: params
  })
}

// 查询所有设备最新采集数据
export function getAllLatestCollectionData() {
  return request({
    url: '/energy/collection/latest/all',
    method: 'get'
  })
}

// 查询设备采集数据质量报告
export function getDataQualityReport(deviceCode, params) {
  return request({
    url: '/energy/collection/quality/' + deviceCode,
    method: 'get',
    params: params
  })
}

// 查询设备采集数据总数
export function getCollectionDataCount(params) {
  return request({
    url: '/energy/collection/count',
    method: 'get',
    params: params
  })
}

// 查询能源数据详细
export function getEnergyData(dataId) {
  return request({
    url: '/energy/monitor/' + dataId,
    method: 'get'
  })
}

// 新增能源数据
export function addEnergyData(data) {
  return request({
    url: '/energy/monitor',
    method: 'post',
    data: data
  })
}

// 批量新增能源数据
export function addEnergyDataBatch(data) {
  return request({
    url: '/energy/monitor/batch',
    method: 'post',
    data: data
  })
}

// 修改能源数据
export function updateEnergyData(data) {
  return request({
    url: '/energy/monitor',
    method: 'put',
    data: data
  })
}

// 删除能源数据
export function delEnergyData(dataId) {
  return request({
    url: '/energy/monitor/' + dataId,
    method: 'delete'
  })
}

// 导出能源数据
export function exportEnergyData(query) {
  return request({
    url: '/energy/monitor/export',
    method: 'post',
    params: query
  })
}

// 清理历史数据
export function cleanHistoryData(beforeTime) {
  return request({
    url: '/energy/monitor/clean/' + beforeTime,
    method: 'delete'
  })
} 